<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">
    /**
     * 审核促销活动商品
     */
    function auditPromotionProduct() {
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            $.ajax({
                type:"post",
				dataType:"json",
                async: false,
                url:"${basePath}/back/promotion/checkPromotionType.sjson",
                data:{promotionId:${promotionId}},
                success:function(data){
                    if(data.success==true){
						$("#btn_auditPromotionProduct").attr("data-target", "#auditPromotionProductModal");/**选中了记录后才可打开对应的模态框**/
						/**隐藏域**/
						$("#applyPromotionId").val(selectedRow[0].applyPromotionId);/**申请促销id**/
						$("#promotionId").val(selectedRow[0].promotionId);/**促销活动Id**/
						/**可见表单控件**/
						if (selectedRow[0].promotionState == 1) {/**状态 0、待审核 1、通过  2、拒绝  3、再次申请**/
							$("#promotionState_1").attr("checked", "checked");
						} else if (selectedRow[0].promotionState == 2) {
							$("#promotionState_2").attr("checked", "checked");
						}
                    }else{
                        showMsg("只有审核通过并且未开启的促销活动才能进行商品审核！");
                    }
                }
            });
        }else {
            $("#btn_auditPromotion").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }

    /**
     * 表单异步提交
     */
    function submitForm_auditPromotionProduct(){
        var options = {
            url: $("#form_auditPromotionProduct").attr("action"),
            type : "post",
            dataType:"json",
            success : function(data) {
                if(data.success==true){
                    /** 先重置查询框的值**/
                    resetQueryForm();
                    /** 重新刷新列表数据**/
                    $("#tt").bootstrapTable('refresh');
                    /** 自动关闭弹出模态框窗口**/
                    $(".close").click();
                    showMsg("保存成功！");
                }else{
                    showMsg("其他促销活动中已经有此商品，暂不能操作！");
                }
            }
        };
        $("#form_auditPromotionProduct").ajaxSubmit(options);
    }
</script>

<!--审核促销活动商品模态框（Modal） -->
<div class="modal fade" id="auditPromotionProductModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel">审核促销活动商品</h5>
			</div>
			<div class="modal-body">
				<form id="form_auditPromotionProduct" method="post" action="${basePath}/back/storeApplyPromotion/approveOrReject.sjson">
					<input id="applyPromotionId" type="hidden" name="applyPromotionId"/>
					<input id="promotionId" type="hidden" name="promotionId" value="${promotionId}"/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>审核状态:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<label class="checkbox-inline">
									<input type="radio" name="promotionState" id="promotionState_1" class="radioInput" value="1" checked="checked">&nbsp;通过
								</label>
								<label class="checkbox-inline">
									<input type="radio" name="promotionState" id="promotionState_2" class="radioInput" value="2"  >&nbsp;拒绝
								</label>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary" onclick="submitForm_auditPromotionProduct()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
